<template>
	<view>
		<!-- 巡检 -->
		<view v-if="state == true">
			<!-- <onSiteIndex ref='onSiteIndex' @getsite='getdate'></onSiteIndex> -->
			<onSiteIndex ref='onSiteIndex' ></onSiteIndex>
		</view>
		<!-- 工长 -->
		<view v-else>
			<foremanIndex ref="foreman" @getlist='getlist'></foremanIndex>
		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	import onSiteIndex from '@/pages/onSite/onSiteIndex.vue'
	import foremanIndex from '@/pages/foreman/foreman.vue'
	import {
		checkUpdate
	} from "@/components/appupdate/js/app-update-check.js";
	export default {
		data() {
			return {
				state: true,
				infoState: ''
			}
		},
		components: {
			onSiteIndex,
			foremanIndex
		},
		computed: {
			...mapGetters(['userInfo'])
		},
		created() {
			// uni.startPullDownRefresh();
			// setTimeout(function() {
			// 	uni.stopPullDownRefresh();
			// }, 1000);

		},
		onShow() {
			if (this.userInfo.roleType == '3' || uni.getStorageSync('userInfo').roleType == '3') {
				uni.setNavigationBarTitle({
					title: '家装顾问-巡检'
				});
				this.state = true
			} else if (this.userInfo.roleType == '2' || uni.getStorageSync('userInfo').roleType == '2') {
				uni.setNavigationBarTitle({
					title: '家装顾问-工长'
				});
				this.state = false
			}
		},
		methods: {
			// onPullDownRefresh() {
			// 	console.log(222);
			// 	if (this.userInfo.roleType == '3' || uni.getStorageSync('userInfo').roleType == '3') {
			// 		this.$refs.onSiteIndex.getdate()
			// 	} else if (this.userInfo.roleType == '2' || uni.getStorageSync('userInfo').roleType == '2') {
			// 		this.$refs.foreman.getlist()
			// 	}
			// 	setTimeout(function() {
			// 		uni.stopPullDownRefresh();
			// 	}, 1000);
			// },
			//获取线上APP版本信息
			getAppInfo(t = 0) {
				// console.log('获取线上')
				const system_info = uni.getSystemInfoSync();
				let type = 1;
				if (system_info.platform == 'android') {
					type == 1;
				} else if (system_info.platform == 'ios') {
					type: 2
				}
				this.$http('version.query', {
					systemType: type,
					appType: 2
				}).then(res => {
					if (res.code == 200) {
						let update_info = {
							version: res.data.version, //线上版本
							// version: '2.0', //线上版本
							now_url: res.data.nowUrl, //更新链接
							// now_url:'http://web.77chaoxun.com/user.apk', //更新链接

							silent: 0, //是否是静默更新
							force: res.data.forces, //是否是强制更新

							net_check: 1, //非WIfi是否提示
							note: res.data.note, //更新内容
						};
						checkUpdate(update_info, t).then(r => {
							if (r.update == 1) {
								//弹出更新
								uni.setStorageSync('updateinfo', update_info)
								uni.redirectTo({
									url: "/pages/appupdate",
									success: function() {

									}

								})


							} else {
								if (res.msg) {
									plus.nativeUI.toast(res.msg);
								}
							}

						}); ///检查更新

					}
				});

			},
		}
	}
</script>

<style>

</style>
